package com.bing.common.enums;

import com.bing.common.constant.CacheKey;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Getter
@AllArgsConstructor
public enum CacheNameEnum {

    FIFTEEN_SECOND(CacheKey.CACHEMANAGER_FIFTEEN_SECOND, TimeUnit.SECONDS,15),

    THIRTY_SECOND(CacheKey.CACHEMANAGER_THIRTY_SECOND, TimeUnit.SECONDS,30),

    ONE_MINUTE(CacheKey.CACHEMANAGER_ONE_MINUTE, TimeUnit.MINUTES,1),

    THREE_MINUTE(CacheKey.CACHEMANAGER_THREE_MINUTE, TimeUnit.MINUTES,3),

    FIVE_MINUTE(CacheKey.CACHEMANAGER_FIVE_MINUTE, TimeUnit.MINUTES,5),

    TEN_MINUTE(CacheKey.CACHEMANAGER_TEN_MINUTE, TimeUnit.MINUTES,10),

    THIRTY_MINUTE(CacheKey.CACHEMANAGER_THIRTY_MINUTE, TimeUnit.MINUTES,30);

    private String name;

    private TimeUnit timeUnit;

    private int effectiveTime;

    private static Map<String,CacheNameEnum> kvMap = new HashMap<>();

    static {
        for(CacheNameEnum item : CacheNameEnum.values()){
            kvMap.put(item.getName(),item);
        }
    }

    public static CacheNameEnum get(String name){
        return kvMap.get(name);
    }

    public Long getSeconds(){
        return TimeUnit.MINUTES.toSeconds(effectiveTime);
    }
}
